// 小和问题
// 测试链接 : https://www.nowcoder.com/practice/edfe05a1d45c4ea89101d936cac32469
#include<vector>
#include<iostream>
using namespace std;
typedef long long int ll;
ll n = 0;
vector<ll>arr(1e5 + 5);
vector<ll>tem(1e5 + 5);

ll merge(ll l, ll m, ll r)
{
    //先进行统计
    //4 5 6   7 8 9
    ll ret = 0, sum = 0;
    for (ll i = m + 1, j = l; i <= r; i++)
    {
        while (j <= m && arr[j] <= arr[i])
            sum += arr[j++];
        ret += sum;
    }

    //merge过程
    ll index = l;
    ll begin1 = l, end1 = m;
    ll begin2 = m + 1, end2 = r;
    while (begin1 <= end1&&begin2<=end2) tem[index++] = arr[begin1] <= arr[begin2] ? arr[begin1++] : arr[begin2++];
    while (begin1 <= end1) tem[index++] = arr[begin1++];
    while (begin2 <= end2) tem[index++] = arr[begin2++];
    for (ll k = l; k <= r; k++) arr[k] = tem[k];
    return ret;
}
ll solve(ll left, ll right)
{
    if (left >= right) return 0;
    ll mid = left + (right - left) / 2;
    return solve(left, mid) + solve(mid + 1, right) + merge(left, mid, right);
}
int main()
{
    cin >> n;
    for (ll i = 0; i < n; i++) cin >> arr[i];
    cout << solve(0, n - 1) << endl;
    //for(int i=0;i<n;i++) cout<<arr[i]<<" ";
    return 0;
}